The fields

Form validation

On the VDoc Platform, the user’s input are validated on the server-side. The field value is being sent to the server and if the validation fails, the response is sent back to the client and a feedback is shown underneath the field.

The VDoc development kit provides a new Framework to develop classes for validating user's input on the server-side.

The Validator Framework gives a standard way for defining :

  • an XML definition file: an association between the name of the validator and its class full qualified name.
  • a validator class: class to execute while validating.

Validator definition

XML definition

The XML validator file should be deployed on the custom/validators folder. Its name must be unique on the VDoc server. To prevent name conflicts it is recommended to use the following template: companyName-validators.xml (e.i. vdoc-validators.xml). This XML definition file provides all the necessary information to describe several validators:

  • Validator name: The name should be unique on the VDoc server.
    Error during retrieving content skip as ignoreDownloadError activated.
  • Validator runtime class: The full qualified name of the validator class to execute while validating a field.
  • parameter: one of the following values: true, false or mandatory. mandatory if the parameter is mandatory, true if the parameter is optional and false if the validator does not required any parameter.
  • options: a set of comma-separated options.
  • hidden: if true, the Framework prevents the validator to appear on the Studio.

Runtime class

A runtime class is a Java class which will be called by the framework when the UI Framework validates any form fields. A runtime class must extend the com.axemble.vdoc.sdk.validators.BaseValidator<T> class. The BaseValidator class uses a generic to validate any kind of object.

By creating a validator runtime class you need to implement two methods:

  • validate(): this method receives the object to validate and the parameters to use for the validation. The return value returns true if the object is valid, false otherwise.

Another method could be overridden:

  • getErrorMessage(): Allows to override a unique error message to display when the validation fails.
Create the runtime class for the validator
package com.axemble.vdoc.education.validators;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.axemble.vdoc.sdk.validators.BaseValidator;

public class DemoValidator extends BaseValidator<String>
{
        @Override
        public boolean validate( String object, List<String> parameters )
        {
                if ( parameters != null && parameters.size() > 0 )
                {
                        String arg = parameters.get( 0 );

                        // checks if the 'arg' parameter is contained within the 'object'
                        boolean ignoreCase = parameters.size() > 1 && parameters.get( parameters.size() - 1 ).equalsIgnoreCase( "--ignorecase" );
                        return ( StringUtils.isNotEmpty( object ) && StringUtils.isNotEmpty( arg ) && ( ignoreCase ? ( object.toLowerCase().indexOf( arg.toLowerCase() ) != -1 ) : ( object.indexOf( arg ) != -1 ) ) );
                }
                return false;
        }

        @Override
        public String getErrorMessage()
        {
                return getStaticString( "LG_DEMO_ERROR_MESSAGE" );
        }
}

Available validators

The VDoc Platform has a wide range of validation functions. Designers can change the default validation behavior by specifying a list of rules on each input field through the property panel within the Form Designer.

Name Description Attributes
alphanumeric The input requires an answer that contains only letters a-z and numbers alphanumeric
alpha The input requires an answer that contains only letters a-z alpha
capitalize The input requires an answer that starts with upper case character capitalize
email The input requires an answer that contains matches the email format email
url The input requires an answer that contains matches the url format url
maxchars The input checks that contains more than maxchars characters maxchars number_of_characters
minchars The input checks that contains less than minchars characters minchars number_of_characters
contains The input checks that the answer contains the specified text contains text --ignorecase
startswith The input checks that the answer starts with the text startswith text --ignorecase
endswith The input checks that the answer ends with the text endswith text --ignorecase
lowercase The input requires an answer with only lower case characters lowercase
uppercase The input requires an answer with only upper case characters uppercase
sysname The input requires an answer that matches the system name rules : - only letters a-z, A-Z, numbers or underscores - no number on first character sysname
extensionformat The input checks that the answer matches the full qualified name for a class. extensionformat
regexp The input checks that the answer matches the expression. Example : The following example allows only lower case letters regexp ^([a-z]+)$ regexp expression --ignorecase --multiline